<div id="app">
    <a href="#">1111</a>
    <a href="#">2222</a>
    <a href="#">3333</a>
    <a href="#">4444</a>
    <a href="#">5555</a>
    <a href="#">6666</a>
    <p>我是ppppp</p>
</div>
<script>
    function addEvent(elem,type,selector,fn){
        //传了三个参数，说明selector没传
        if(fn==null){
            fn = selector
            selector = null
        }
        elem.addEventListener(type,event=>{
            const target = event.target
            console.log(target);
            if(selector){
                //有指定子标签
                if(target.matches(selector)){
                    fn.call(target,event)
                }
            }else{
                //没有指定
                fn.call(target,event)
            }
        })

    }
    let app = document.querySelector('#app')
    addEvent(app,'click','a',function(event){
        event.preventDefault()
        alert(this.innerHTML)
    })
</script>